package org.jeecg.modules.friends.dao.impl;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.jeecg.modules.friends.condition.TicketRecordCondition;
import org.jeecg.modules.friends.mapper.ext.TicketRecordDOExtMapper;
import org.jeecg.modules.friends.model.TicketRecordDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TicketRecordDAOImpl implements org.jeecg.modules.friends.dao.TicketRecordDAO {
    @Autowired
    private TicketRecordDOExtMapper ticketRecordDOExtMapper;

    @Override
    public void insert(TicketRecordDO recordDO) {
        ticketRecordDOExtMapper.insert(recordDO);
    }

    @Override
    public TicketRecordDO findByUserIdAndApplyId(Long userId, Long applyId) {
        TicketRecordCondition ticketRecordCondition = new TicketRecordCondition();
        TicketRecordCondition.Criteria criteria = ticketRecordCondition.createCriteria();
        criteria.andUserIdEqualTo(userId);
        criteria.andFriendApplyIdEqualTo(applyId);
        List<TicketRecordDO> ticketRecordDOList = ticketRecordDOExtMapper.selectByCondition(ticketRecordCondition);
        return CollectionUtils.isEmpty(ticketRecordDOList) ? null : ticketRecordDOList.get(0);
    }

    @Override
    public void updateValidStatus(Long id, int status) {
        TicketRecordDO ticketRecordDO = new TicketRecordDO();
        ticketRecordDO.setId(id);
        ticketRecordDO.setValidStatus(status);
        ticketRecordDOExtMapper.updateByPrimaryKeySelective(ticketRecordDO);
    }

    @Override
    public TicketRecordDO findById(Long friendInfoId) {
        return ticketRecordDOExtMapper.selectByPrimaryKey(friendInfoId);
    }
}